package com.wc.alorithm_luogu.P5734;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/23 11:01
 * @description https://www.luogu.com.cn/problem/P5734
 * 文字处理软件
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.nextLine());
        String s = sc.nextLine();
        StringBuilder curStr = new StringBuilder(s);
        StringBuilder ans = new StringBuilder();

        while (n-- > 0) {
            String[] split = sc.nextLine().split(" ");

            switch (split[0]) {
                case "1": {
                    curStr.append(split[1]);
                    ans.append(curStr);
                    ans.append('\n');
                    break;
                }
                case "2": {
                    int a = Integer.parseInt(split[1]);
                    int b = Integer.parseInt(split[2]);
                    CharSequence charSequence = curStr.subSequence(a, a + b);
                    curStr = new StringBuilder(charSequence);
                    ans.append(curStr);
                    ans.append('\n');
                    break;
                }
                case "3": {
                    int a = Integer.parseInt(split[1]);
                    curStr.insert(a, split[2]);
                    ans.append(curStr);
                    ans.append('\n');
                    break;
                }
                case "4": {
                    int i = curStr.toString().indexOf(split[1]);
                    ans.append(i);
                    ans.append('\n');
                }
            }
        }
        System.out.print(ans);
    }
}
